package com18;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

public class twofillter implements Filter {
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest request= (HttpServletRequest) servletRequest;
        HttpSession session=request.getSession(false);
        HttpServletResponse response= (HttpServletResponse) servletResponse;
        String s="http://localhost:8080/web4/denlu";
        String s1="http://localhost:8080/web4/denlu.html";
        System.out.println("twofilter"+session);
        if (session==null&&!(s.equals(request.getRequestURL()+""))
                &&!(s1.equals(request.getRequestURL()+"")))
        {
            System.out.println("meiyoi"+request.getRequestURL());
            request.getRequestDispatcher("/error").forward(servletRequest,servletResponse);
            return;
        }
        filterChain.doFilter(servletRequest,servletResponse);
    }
}
